package com.sanploy.manage.controller;


import com.sanploy.common.domain.dto.MessageDto;
import com.sanploy.common.domain.dto.Pages;
import com.sanploy.manage.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhu yingzhi on 2017/9/6.
 * @author yingzhi zhu
 * 后台消息请求路由类
 */
@RestController
@RequestMapping("/message")
public class MessageController
{
    @Autowired
    private MessageService messageService;


    /**
     * 按是否已读 分页获取所有的消息
     * @param is_read 是否已读
     * currentPage; 当前页码
       pageSize;页数
     * @return
     */
    @GetMapping("")
    public Object getAllMessages(Pages pages,@RequestParam boolean is_read){
        return messageService.getAllMessage(pages,is_read);
    }

    /**
     * 查找消息的数量
     * @param is_read 是否已读
     * @return
     */
    @GetMapping("/count")
    public Object countOfReadMessages(@RequestParam boolean is_read){
        return messageService.countMessage(is_read);
    }


    /**
     * 测试上传消息
     * @param message
     * @return
     */
    @PostMapping("")
    public Object testAddMsg(MessageDto message){
        return messageService.addMessage(message);
    }

    /**
     * 根据id查找某个商品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Object findOneMsg(@PathVariable Long id){
        return messageService.findById(id);
    }

    /**
     * 批量设置id为已读
     * @param id_arr id数组 1,2,3
     * @return
     */
    @GetMapping("/read")
    public Object setRead(String[] id_arr){
        return messageService.setIsReadMsg(id_arr);
    }


    /**
     * 获取新消息接口
     * @return
     */
    @GetMapping("/newMessage")
    public Object newMessage(){
        return messageService.newMessage();
    }


}
